﻿
Partial Class WebForm_Form_otherTelNo
    Inherits BaseUserControl
    Public Sub InitDataAndShow(ByVal FormNo As Integer, ByVal ApplyType As String)
        If ApplyType = "3" Then
            gvApplyDetail.Columns(1).Visible = True
        ElseIf ApplyType = "A" Then ''非申請時開窗用
            gvApplyDetail.Columns(1).Visible = True
            gvApplyDetail.Columns(0).Visible = False
            btnOK.Visible = False
        Else
            gvApplyDetail.Columns(1).Visible = False

        End If


        hiFormNo.Value = FormNo.ToString
        Me.mpSearch.Show()
    End Sub

   
    Protected Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
        hiKind.Value = "1"
        gvApplyDetail.PageIndex = 0
        gvApplyDetail.EditIndex = 0
        gvApplyDetail.DataBind()
        mpSearch.Show()

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then

            hidbName.Value = dbName
           
        End If
    End Sub

    Protected Sub gvApplyDetail_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvApplyDetail.DataBound
        mpSearch.Show()
    End Sub

    Protected Sub gvApplyDetail_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvApplyDetail.PageIndexChanged
        hiKind.Value = ""
        gvApplyDetail.DataBind()
    End Sub

    Protected Sub gvApplyDetail_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvApplyDetail.SelectedIndexChanged
        hiKind.Value = ""
        gvApplyDetail.DataBind()
    End Sub

    Protected Sub gvApplyDetail_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles gvApplyDetail.RowCancelingEdit
        hiKind.Value = ""
        gvApplyDetail.DataBind()
    End Sub

    Protected Sub gvApplyDetail_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles gvApplyDetail.RowUpdated
        hiKind.Value = ""
        gvApplyDetail.DataBind()
    End Sub

    Protected Sub gvApplyDetail_RowDeleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeletedEventArgs) Handles gvApplyDetail.RowDeleted
      
    End Sub

    Protected Sub gvApplyDetail_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gvApplyDetail.RowDeleting

        Dim telno As String = CType(gvApplyDetail.Rows(e.RowIndex).FindControl("hiTelNo"), HiddenField).Value
        Dim dao As Telecom.DAO.ApplyDAO = New Telecom.DAO.ApplyDAO(hidbName.Value)
        dao.DeleteDetail(Integer.Parse(hiFormNo.Value), telno)
        e.Cancel = True
        hiKind.Value = ""
        gvApplyDetail.DataBind()

    End Sub

    Protected Sub gvApplyDetail_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvApplyDetail.RowUpdating
        Dim telno As String = CType(gvApplyDetail.Rows(e.RowIndex).Cells(2).Controls(0), TextBox).Text
        Dim dao As Telecom.DAO.ApplyDAO = New Telecom.DAO.ApplyDAO(hidbName.Value)
        If dao.ChkDetail(Integer.Parse(hiFormNo.Value), telno) Then
            ShowMessageForAjax(btnCancel, "電話已重覆.無法存檔")
            e.Cancel = True
        End If
        mpSearch.Show()
       
    End Sub
End Class
